package cn.t12.qg.userprovider.service;

import cn.t12.qg.service.user.UserService;
import cn.t12.qg.userprovider.mapper.UserMapper;
import com.qg.pojo.QgUser;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

@DubboService(version = "1.0.0",interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public QgUser login(String phone, String password) {
        // 根据phone查询
        QgUser qgUser = userMapper.selectByPhone(phone);
        if (qgUser == null) {
            return null;
        }
        // 比较密码是否正确
        // 先对password进行加密,在比较 ...
        if (!qgUser.getPassword().equals(password)) {
            return null;
        }
        // 返回登录用户信息
       return qgUser;
    }

    @Override
    public QgUser loginByOpenId(String openId) {
        return userMapper.selectByOpenId(openId);
    }

    @Override
    public boolean exists(String openId) {
        return userMapper.selectByOpenId(openId) != null;
    }

    @Override
    public void register(QgUser qgUser) {
        userMapper.insertQgUser(qgUser);
    }
}
